import java.util.ArrayList;
import java.util.List;

class Originator {
    private String state;

    public Memento createMemento(String state) {
        return new Memento(state);
    }
    
    public void setMemento(Memento memento) {
        state = memento.getState();
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getState() {
        return state;
    }
}

class Memento {
    private String state;

    public Memento(String state) {
        this.state = state;
    }

    public String getState() {
        return state;
    }
}

class Caretaker {
    private List<Memento> list = new ArrayList<Memento>();

    public void addMemento(Memento memento) {
        list.add(memento);
    }

    public Memento getMemento(int index) {
        return list.get(index - 1);
    }
    
    public void showMemento() {
        int cnt = 1;
        for (Memento memento : list) {
            System.out.println("memento: " + cnt);
            cnt++;
        }
    }


}

class test {
    public static void main(String[] args) {
        Caretaker caretaker = new Caretaker();
        Originator originator = new Originator();

        originator.setState("1");
        Memento back1 = originator.createMemento(null);
        caretaker.addMemento(back1);

        System.out.println(originator.getState());

        caretaker.showMemento();

    }


}